﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="Scripts/jquery-3.3.1.min.js"></script>
    <script src="Scripts/jquery.signalR-2.2.2.js"></script>
    <script src="/signalr/hubs" type="text/javascript"></script>
</head>
<body>
    <button id="btn2">getPerson</button><br />
    <script>
       
        $("#btn2").click(function () {

            $.connection.testHub.server.getPerson().done(function (p) {
                alert("收到服务端信息:" + p.id + "|" + p.name);
            });
            //.fail(function () {
            //    alert("fail...");
            //    });
        });
    </script>

    <input type="text" id="userName" /><br />
    <input type="text" id="message" /><br />
    <button id="btn1">click</button>
    <script>
        $.connection.testHub.client.onMessage = function (userName, msg) {
            alert("收到服务端信息:" + userName + "|" + msg);
        };

        $.connection.testHub.client.onServerError = function (msg) {
            alert(msg);
        };

        $.connection.hub.start().done(function () {
            alert("done");
        }).fail(function () {
            alert("fail");
        });

        $("#btn1").click(function () {
            var userName = $("#userName").val();
            var message = $("#message").val();
            $.connection.testHub.server.sendMessage(userName, message);
        });
    </script>
</body>
</html>